package cn.edu.zut.service.impl;

import cn.edu.zut.dao.IBookDao;
import cn.edu.zut.service.IBookService;
import cn.edu.zut.domin.Book;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class BookServiceImpl implements IBookService {

    @Autowired
    private IBookDao iBookDao;

    @Override
    public void saveBook(Book book) throws Exception{
        iBookDao.saveBook(book);
    }

    @Override
    public List<Book> findAll(int page,int size) throws Exception {
        PageHelper.startPage(page,size);
        return iBookDao.findAll();
    }

    /**
     * 查询所有图书的信息
     * @return
     * @throws Exception
     */
    @Override
    public List<Book> findAll() throws Exception {
        return iBookDao.findAll();
    }

    @Override
    public List<Book> findBookById(String id) throws Exception {
        return iBookDao.findBookById(id);
    }

    @Override
    public void deleteBook(String id) throws Exception {
        iBookDao.deleteBook(id);
    }

    @Override
    public void updateBook(Book book) throws Exception {
        iBookDao.updateBook(book);
    }

    @Override
    public List<Book> findBookByName(String name) throws Exception {
        return iBookDao.findBookByName(name);
    }

    @Override
    public List<Book> findBookByPublisher(String name) throws Exception {
        return iBookDao.findBookByPublisher(name);
    }

    @Override
    public List<Book> findBookByNameMOHU(String name) throws Exception {
        return iBookDao.findBookByNameMOHU(name);
    }

    @Override
    public List<Book> selectBookLendInfoByBookId(String Id)
    {
        List<Book> book=iBookDao.selectBookLendInfoByBookId(Id);
        return book;
    }

    @Override
    public List<Book> selectAllBookLendInfoByBookId() {
        List<Book> books=iBookDao.selectAllBookLendInfoByBookId();
        return books;
    }
}
